{include file="header.htm" /}
<body class="bodystyle" style="cursor: default; -moz-user-select: inherit; min-width:400px;">
<div id="append_parent"></div>
<div id="ajaxwaitid"></div>
<style type="text/css">
    .ncap-form-default dt.tit {width: 120px;}
    .ncap-form-default .input-txt {width: 100px !important;}
    .layui-layer-btn .layui-layer-btn0 {border-color: #4fc0e8; background-color: #4fc0e8}
</style>
<div class="page" style="min-width: 400px;">
    {include file="bar.htm" /}
    <div class="flexigrid">
        <form id="dealerPost">
            <div class="ncap-form-default">
                <dl class="row">
                    <dt class="tit">
                        <label>分销功能</label>
                    </dt>
                    <dd class="opt">
                        <label class="curpoin">
                            <input type="radio" name="dealer[dealer_open]" value="1" {if condition="$dealerConfig.dealer_open == 1"} checked="checked" {/if} onclick="dealerOpen(1);">开启
                        </label>
                         &nbsp;&nbsp;&nbsp;
                        <label class="curpoin">
                            <input type="radio" name="dealer[dealer_open]" value="0" {if condition="$dealerConfig.dealer_open == 0"} checked="checked" {/if} onclick="dealerOpen(0);">关闭
                        </label>
                    </dd>
                </dl>
                <div id="dealer_open" {if condition='empty($dealerConfig.dealer_open) || 0 == $dealerConfig.dealer_open'} class="none" {/if}>
                    <dl class="row">
                        <dt class="tit">
                            <label>分销商层级</label>
                        </dt>
                        <dd class="opt">
                            <label class="curpoin">
                                <input type="radio" name="dealer[dealer_level]" value="1" {if condition="$dealerConfig.dealer_level == 1"} checked="checked" {/if} onclick="dealerLevel(1);" id="1_dealer_level">一级分销商
                            </label>
                             &nbsp;&nbsp;&nbsp;
                            <label class="curpoin">
                                <input type="radio" name="dealer[dealer_level]" value="2" {if condition="$dealerConfig.dealer_level == 2"} checked="checked" {/if} onclick="dealerLevel(2);" id="2_dealer_level">二级分销商
                            </label>
                            <p class="notic">
                                1.一级分销商模式，冻结所有二级分销商所有分销能力<br>
                                2.二级分销商模式，恢复所有二级分销商所有分销能力
                            </p>
                        </dd>
                    </dl>

                    <dl class="row">
                        <dt class="tit">
                            <label>分销商自购</label>
                        </dt>
                        <dd class="opt">
                            <label class="curpoin">
                                <input type="radio" name="dealer[dealer_self_buy]" value="1" {if condition="$dealerConfig.dealer_self_buy == 1"} checked="checked" {/if}>开启
                            </label>
                             &nbsp;&nbsp;&nbsp;
                            <label class="curpoin">
                                <input type="radio" name="dealer[dealer_self_buy]" value="0" {if condition="$dealerConfig.dealer_self_buy == 0"} checked="checked" {/if}>关闭
                            </label>
                            <p class="notic">
                                1.开启自购，分销商自购时，自身获得一级佣金，如果存在上级分销商则上级分销商获得二级佣金<br>
                                2.关闭自购，分销商自购时，自身不获得佣金，如果存在上级分销商则上级分销商获得一级佣金
                            </p>
                        </dd>
                    </dl>

                    <dl class="row">
                        <dt class="tit">
                            <label>佣金计算方式</label>
                        </dt>
                        <dd class="opt">
                            <label class="curpoin">
                                <input type="radio" name="dealer[dealer_rebate]" value="1" {if condition="$dealerConfig.dealer_rebate == 1"} checked="checked" {/if} onclick="dealerRebate(1);" id="1_dealer_rebate">订单商品合计总额
                            </label>
                             &nbsp;&nbsp;&nbsp;
                            <label class="curpoin">
                                <input type="radio" name="dealer[dealer_rebate]" value="2" {if condition="$dealerConfig.dealer_rebate == 2"} checked="checked" {/if} onclick="dealerRebate(2);" id="2_dealer_rebate">订单实际支付总额
                            </label>
                            <p class="notic">
                                1.订单商品合计总额，即订单内所有商品实际购买价格总和<br>
                                2.订单实际支付总额，即订单支付时实际支付金额总和
                            </p>
                        </dd>
                    </dl>

                    <dl class="row">
                        <dt class="tit">
                            <label>佣金结算方式</label>
                        </dt>
                        <dd class="opt">
                            <label class="curpoin">
                                <input type="radio" name="dealer[dealer_settlement]" value="1" {if condition="$dealerConfig.dealer_settlement == 1"} checked="checked" {/if} onclick="dealerSettlement(1);" id="1_dealer_settlement">订单完成立即结算
                            </label>
                             &nbsp;&nbsp;&nbsp;
                            <label class="curpoin">
                                <input type="radio" name="dealer[dealer_settlement]" value="2" {if condition="$dealerConfig.dealer_settlement == 2"} checked="checked" {/if} onclick="dealerSettlement(2);" id="2_dealer_settlement">自定义结算天数
                            </label>
                            <p class="notic">
                                1.分销订单在会员确认收货或商家确认完成时立即对订单进行结算<br>
                                2.分销订单在会员确认收货或商家确认完成后根据自定义结算天数进行结算
                            </p>
                        </dd>
                    </dl>

                    <dl class="row {if condition='empty($dealerConfig.dealer_settlement) || 2 != $dealerConfig.dealer_settlement'}none{/if}" id="dealer_settlement_2">
                        <dt class="tit">
                            <label></label>
                        </dt>
                        <dd class="opt">
                            订单确认收货 <input type="text" name="dealer[dealer_settlement_day]" value="{$dealerConfig.dealer_settlement_day|default='12'}" class="input-txt" onpaste="this.value=this.value.replace(/[^\d]/g, '');" onkeyup="this.value=this.value.replace(/[^\d]/g, ''); minimumLimit(this, 1);"/> 天后自动结算
                            <p class="notic">自动结算时间至少1天，建议设置的结算天数大于 【商城中心-商城配置-订单设置-收货后可维权时间】 设置的天数，否则会出现佣金结算后商品被维权的情况，切勿随意修改，修改后立即生效</p>
                        </dd>
                    </dl>

                    <dl class="row" id="dealer_level_1">
                        <dt class="tit">
                            <label>一级佣金比例</label>
                        </dt>
                        <dd class="opt">
                            <input type="text" name="dealer[dealer_one_level_rebate]" value="{$dealerConfig.dealer_one_level_rebate|default='10'}" class="input-txt" onpaste="this.value=this.value.replace(/[^\d]/g, '');" onkeyup="this.value=this.value.replace(/[^\d]/g, ''); minimumLimit(this, 1);"/> %
                            <p class="notic">会员购买完成，订单结算佣金时，如果有所属分销商，则给所属分销商的佣金比例</p>
                        </dd>
                    </dl>

                    <dl class="row {if condition='1 == $dealerConfig.dealer_level'}none{/if}" id="dealer_level_2">
                        <dt class="tit">
                            <label>二级佣金比例</label>
                        </dt>
                        <dd class="opt">
                            <input type="text" name="dealer[dealer_two_level_rebate]" value="{$dealerConfig.dealer_two_level_rebate|default='5'}" class="input-txt" onpaste="this.value=this.value.replace(/[^\d]/g, '');" onkeyup="this.value=this.value.replace(/[^\d]/g, ''); minimumLimit(this, 1);"/> %
                            <p class="notic">会员购买完成，订单结算佣金时，所属分销商如果有上级分销商，则给上级分销商佣金比例</p>
                        </dd>
                    </dl>

                    <dl class="row none">
                        <dt class="tit">
                            <label>商品详情展示佣金</label>
                        </dt>
                        <dd class="opt">
                            <label class="curpoin">
                                <input type="radio" name="dealer[dealer_show_rebates]" value="1" {if condition="$dealerConfig.dealer_show_rebates == 1"} checked="checked" {/if}>开启
                            </label>
                             &nbsp;&nbsp;&nbsp;
                            <label class="curpoin">
                                <input type="radio" name="dealer[dealer_show_rebates]" value="0" {if condition="$dealerConfig.dealer_show_rebates == 0"} checked="checked" {/if}>关闭
                            </label>
                            <p class="notic">
                                1.开启后，商品详情显示<br>
                                2.关闭后，商品详情不显示
                            </p>
                        </dd>
                    </dl>

                    <dl class="row">
                        <dt class="tit">
                            <label>绑定下级条件</label>
                        </dt>
                        <dd class="opt">
                            <label class="curpoin">
                                <input type="radio" name="dealer[dealer_bind_condition]" value="1" checked="checked">首次点击分享海报
                            </label>
                            <!--  &nbsp;&nbsp;&nbsp;
                            <label class="curpoin"> <input type="radio" name="dealer[dealer_bind_condition]" value="2" {if condition="$dealerConfig.dealer_bind_condition == 2"} checked="checked" {/if}>首次下单 </label>
                             &nbsp;&nbsp;&nbsp;
                            <label class="curpoin"> <input type="radio" name="dealer[dealer_bind_condition]" value="3" {if condition="$dealerConfig.dealer_bind_condition == 3"} checked="checked" {/if}>首次付款 </label> -->
                            <p class="notic">普通用户在扫码识别分销商的分享海报进入后即可成为该分销商的下线<br></p>
                            <!-- <p class="notic">1.普通用户在点击分销商的分享链接后即可成为该分销商的下线<br>2.普通用户在点击分销商的分享链接后在商城中创建订单即可成为该分销商的下线<br>3.普通用户在点击分销商的分享链接后在商城中创建订单并支付成功即可成为该分销商的下线</p> -->
                        </dd>
                    </dl>

                    <dl class="row">
                        <dt class="tit">
                            <label>申请分销商方式</label>
                        </dt>
                        <dd class="opt">
                            <!-- <label class="curpoin"> <input type="radio" name="dealer[dealer_apply_type]" value="1" {if condition="$dealerConfig.dealer_apply_type == 1"} checked="checked" {/if} onclick="dealerApplyType(1);">无条件 </label>
                             &nbsp;&nbsp;&nbsp;
                            <label class="curpoin"> <input type="radio" name="dealer[dealer_apply_type]" value="2" {if condition="$dealerConfig.dealer_apply_type == 2"} checked="checked" {/if} onclick="dealerApplyType(2);">消费次数 </label>
                             &nbsp;&nbsp;&nbsp;
                            <label class="curpoin"> <input type="radio" name="dealer[dealer_apply_type]" value="3" {if condition="$dealerConfig.dealer_apply_type == 3"} checked="checked" {/if} onclick="dealerApplyType(3);">消费金额 </label>
                             &nbsp;&nbsp;&nbsp;
                            <label class="curpoin"> <input type="radio" name="dealer[dealer_apply_type]" value="4" {if condition="$dealerConfig.dealer_apply_type == 4"} checked="checked" {/if} onclick="dealerApplyType(4);">后台设置 </label>
                             &nbsp;&nbsp;&nbsp; -->
                            <label class="curpoin">
                                <input type="radio" name="dealer[dealer_apply_type]" value="5" checked="checked" onclick="dealerApplyType(5);">自主申请
                            </label>
                            <p class="notic">用户在会员中心主动申请分销商，后台审核成功即可成为分销商</p>
                            <!-- <p class="notic">1.用户注册成为商城会员即成为分销商<br>2.当消费次数达到一定数量才可以成为分销商<br>3.当消费金额达到一定数量才可以成为分销商<br>4.只能在后台进行添加分销商，前台会员无法进行申请<br>5.小程序自动申请分销商，审核成功即可成为分销商</p> -->
                        </dd>
                    </dl>
                    <!-- <dl class="row {if condition='empty($dealerConfig.dealer_apply_type) || 2 != $dealerConfig.dealer_apply_type'}none{/if}" id="dealer_apply_type_2">
                        <dt class="tit">
                            <label>累计消费次数</label>
                        </dt>
                        <dd class="opt">
                            <input type="number" name="dealer[dealer_cumulative_buy]" value="{$dealerConfig.dealer_cumulative_buy|default='60'}" class="input-txt"/> 次
                            <p class="notic">当消费次数达到一定数量并且订单完成后才可以成为分销商</p>
                        </dd>
                    </dl>
                    <dl class="row {if condition='empty($dealerConfig.dealer_apply_type) || 3 != $dealerConfig.dealer_apply_type'}none{/if}" id="dealer_apply_type_3">
                        <dt class="tit">
                            <label>累计消费金额</label>
                        </dt>
                        <dd class="opt">
                            <input type="number" name="dealer[dealer_cumulative_money]" value="{$dealerConfig.dealer_cumulative_money|default='1000'}" class="input-txt"/> 元
                            <p class="notic">当消费金额达到一定数量并且订单完成后才可以成为分销商</p>
                        </dd>
                    </dl> -->
                    <dl class="row">
                        <dt class="tit">
                            <label>最低提现额度</label>
                        </dt>
                        <dd class="opt">
                            <input type="text" name="dealer[dealer_least_withdrawal]" value="{$dealerConfig.dealer_least_withdrawal|default='1'}" class="input-txt" onpaste="this.value=this.value.replace(/[^\d]/g, '');" onkeyup="this.value=this.value.replace(/[^\d]/g, ''); minimumLimit(this, 1);"/> 元
                            <p class="notic">提现额度最低可设置为1元</p>
                        </dd>
                    </dl>
                </div>
                <div class="bot">
                    <a href="JavaScript:void(0);" class="ncap-btn-big ncap-btn-green" onclick="formSubmit();">保存设置</a>
                </div>
            </div>
        </form>
    </div>
</div>

<script type="text/javascript">
    // 分销商开启关闭
    function dealerOpen(value) {
        $('#dealer_open').hide();
        if (1 === parseInt(value)) $('#dealer_open').show();
    }

    // 分销商等级设置
    var levelValue = "{$dealerConfig.dealer_level|default='0'}";
    function dealerLevel(value) {
        // 如果第一次填写配置则不执行
        if (parseInt(levelValue) === 0) return false;

        // 点击当前结算方式则返回结束
        if (parseInt(value) === parseInt(levelValue)) return false;

        var msg = '';
        if (1 === parseInt(value)) {
            msg = '一级分销商模式，则冻结二级分销商的分销能力，确认操作？';
        } else if (2 === parseInt(value)) {
            msg = '二级分销商模式，则恢复二级分销商的分销能力，确认操作？';
        }
        msg = msg + '<br/>确认并保存设置，则实时生效！';
        layer.confirm(msg, {
            shade: layer_shade,
            area: ['480px', '190px'],
            move: false,
            title: '提示',
            btnAlign:'r',
            closeBtn: 3,
            btn: ['确认','取消'], //按钮
            success: function () {
                $(".layui-layer-content").css('text-align', 'left');
                // $(".layui-layer-btn .layui-layer-btn0").css('border-color', '#4fc0e8');
                // $(".layui-layer-btn .layui-layer-btn0").css('background-color', '#4fc0e8');
            }
        }, function() {
            levelValue = value;
            if (1 === parseInt(value)) {
                $('#dealer_level_2').hide();
            } else if (2 === parseInt(value)) {
                $('#dealer_level_2').show();
            }
            layer.closeAll();
        }, function(index) {
            if (1 === parseInt(value)) {
                $('#1_dealer_level').attr('checked', false);
                $('#2_dealer_level').attr('checked', true);
            } else if (2 === parseInt(value)) {
                $('#1_dealer_level').attr('checked', true);
                $('#2_dealer_level').attr('checked', false);
            }
            layer.closeAll(index);
        });
    }

    // 分销商佣金计算方式
    var rebateValue = "{$dealerConfig.dealer_rebate|default='0'}";
    function dealerRebate(value) {
        // 如果第一次填写配置则不执行
        if (parseInt(rebateValue) === 0) return false;

        // 点击当前结算方式则返回结束
        if (parseInt(value) === parseInt(rebateValue)) return false;

        var msg = '';
        if (1 === parseInt(value)) {
            msg = '确认使用 订单商品合计总额 计算方式？';
        } else if (2 === parseInt(value)) {
            msg = '确认使用 订单实际支付总额 计算方式？';
        }
        msg = msg + '确认并保存设置，则实时生效！';
        layer.confirm(msg, {
            shade: layer_shade,
            area: ['480px', '190px'],
            move: false,
            title: '提示',
            btnAlign:'r',
            closeBtn: 3,
            btn: ['确认','取消'], //按钮
            success: function () {
                $(".layui-layer-content").css('text-align', 'left');
            }
        }, function() {
            rebateValue = value;
            layer.closeAll();
        }, function(index) {
            if (1 === parseInt(value)) {
                $('#1_dealer_rebate').attr('checked', false);
                $('#2_dealer_rebate').attr('checked', true);
            } else if (2 === parseInt(value)) {
                $('#1_dealer_rebate').attr('checked', true);
                $('#2_dealer_rebate').attr('checked', false);
            }
            layer.closeAll(index);
        });
    }

    // 分销商佣金结算方式
    var settlementValue = "{$dealerConfig.dealer_settlement|default='0'}";
    function dealerSettlement(value) {
        // 如果第一次填写配置则不执行
        if (parseInt(settlementValue) === 0) {
            if (1 === parseInt(value)) {
                $('#dealer_settlement_2').hide();
            } else if (2 === parseInt(value)) {
                $('#dealer_settlement_2').show();
            }
            return false;
        }
        // 点击当前结算方式则返回结束
        if (parseInt(value) === parseInt(settlementValue)) return false;

        var msg = '';
        if (1 === parseInt(value)) {
            msg = '确认使用 订单完成立即结算 结算方式？';
        } else if (2 === parseInt(value)) {
            msg = '确认使用 自定义结算天数 结算方式？';
        }
        msg = msg + '确认并保存设置，则实时生效！';
        layer.confirm(msg, {
            shade: layer_shade,
            area: ['480px', '190px'],
            move: false,
            title: '提示',
            btnAlign:'r',
            closeBtn: 3,
            btn: ['确认','取消'], //按钮
            success: function () {
                if (1 === parseInt(value)) {
                    $('#dealer_settlement_2').hide();
                } else if (2 === parseInt(value)) {
                    $('#dealer_settlement_2').show();
                }
                $(".layui-layer-content").css('text-align', 'left');
            }
        }, function() {
            settlementValue = value;
            layer.closeAll();
        }, function(index) {
            if (1 === parseInt(value)) {
                $('#1_dealer_settlement').attr('checked', false);
                $('#2_dealer_settlement').attr('checked', true);
            } else if (2 === parseInt(value)) {
                $('#1_dealer_settlement').attr('checked', true);
                $('#2_dealer_settlement').attr('checked', false);
            }
            if (1 === parseInt(settlementValue)) {
                $('#dealer_settlement_2').hide();
            } else if (2 === parseInt(settlementValue)) {
                $('#dealer_settlement_2').show();
            }
            layer.closeAll(index);
        });
    }

    // 最小值限制
    function minimumLimit(obj, minValue) {
        var value = $(obj).val();
        if (minValue > parseInt(value)) {
            $(obj).val(parseInt(minValue));
        } else {
            value && $(obj).val(parseInt(value));
        }
    }

    // 申请分销商方式
    function dealerApplyType(value) {
        $('#dealer_apply_type_2, #dealer_apply_type_3').hide();
        if (2 === parseInt(value) || 3 === parseInt(value)) $('#dealer_apply_type_' + value).show();
    }

    // 提交分销商配置
    function formSubmit() {
        layer_loading("正在处理");
        $.ajax({
            type: 'post',
            url : "{:weapp_url('DealerPlugin/DealerPlugin/dealer_config', ['_ajax'=>1])}",
            data: $('#dealerPost').serialize(),
            dataType: 'json',
            success: function(res) {
                layer.closeAll();
                if (res.code == 1) {
                    layer.msg(res.msg, {time: 1500}, function() {
                        window.location.reload();
                    });
                } else {
                    showErrorMsg(res.msg);
                }
            },
            error: function(e){
                layer.closeAll();
                showErrorAlert(e.responseText);
            }
        });
    }
</script>

{include file="footer.htm" /}